package com.hotec.PROJECT_NAME.modules.wx.controller;

import com.hotec.PROJECT_NAME.component.basic.BaseController;
import com.hotec.PROJECT_NAME.component.basic.JsonContent;
import com.hotec.PROJECT_NAME.modules.wx.args.WxLoginArgs;
import com.hotec.PROJECT_NAME.modules.wx.args.WxConsumeRegistryArgs;
import com.hotec.PROJECT_NAME.modules.wx.args.WxShopBindArgs;
import com.hotec.PROJECT_NAME.modules.wx.service.WxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("wx")
public class WxController extends BaseController {
    @Autowired
    private WxService wxService;

    /**
     * 根据code获取openid（消费端）
     * @param code
     * @return
     */
    @GetMapping("consume/getOpenIdByCode")
    public JsonContent consumeGetOpenIdByCode (@RequestParam String code){
        return this.success(wxService.consumeGetOpenIdByCode(code));
    }

    /**
     * 注册（消费端）
     * @param wxRegistryArgs
     * @return
     */
    @PostMapping("consume/registry")
    public JsonContent consumeRegistry (@RequestBody WxConsumeRegistryArgs wxRegistryArgs){
        return this.success(wxService.consumeRegistry(wxRegistryArgs));
    }

    /**
     * 根据code获取openid（商户端）
     * @param code
     * @return
     */
    @GetMapping("shop/getOpenIdByCode")
    public JsonContent shopGetOpenIdByCode (@RequestParam String code){
        return this.success(wxService.shopGetOpenIdByCode(code));
    }

    /**
     * 登录（通用）
     * @param wxLoginArgs
     * @return
     */
    @PostMapping("login")
    public JsonContent loginByOpenId (@RequestBody WxLoginArgs wxLoginArgs){
        return this.success(wxService.loginByOpenId(wxLoginArgs));
    }

    /**
     * 退出登录（通用）
     * @return
     */
    @PostMapping("logout")
    public JsonContent logout (){
        wxService.logoutByOpenId();

        return this.success();
    }

    /**
     * 控制信息（通用）
     * @return
     */
    @GetMapping("control")
    public JsonContent control (HttpServletRequest request, @RequestParam Integer version){
        return this.success("操作成功", wxService.control(request, version), false);
    }
}
